<script setup>
const props = defineProps({
  modelValue: {
    type: [String, Number],
    required: true,
  },
  tips: {
    type: String,
    default: "",
  },
  name: {
    type: String,
    default: "滑块",
  },
  min: {
    type: Number,
    default: 0,
  },
  max: {
    type: Number,
    default: 100,
  },
});

const emits = defineEmits(["update:modelValue", "change"]);

const onChange = (value) => {
  emits("update:modelValue", value);
  emits("change", value);
};
</script>
<template>
  <el-form-item>
    <template #label>
      <div class="flex-container">
        <span>{{ name }}</span>
        <template v-if="tips">
          <el-tooltip effect="dark" :content="tips" placement="top">
            <el-icon><InfoFilled /></el-icon>
          </el-tooltip>
        </template>
      </div>
    </template>
    <div class="slider">
      <el-slider
        :model-value="modelValue"
        :min="min"
        :max="max"
        @input="onChange"
      /><span style="margin-left: 10px">{{ modelValue }}px</span>
    </div>
  </el-form-item>
</template>
<style lang="scss" scoped>
.slider {
  display: flex;
  align-items: center;
  margin-left: 10px;
  .el-slider {
    width: 350px;
    max-width: calc(100% - 40px);
  }
}
.flex-container {
  display: flex;
  align-items: center;
  .el-icon {
    cursor: pointer;
  }
}
</style>
